# Maintainer:
pkgname=libime
pkgver=1.1.3
pkgrel=0
_kenlm=bcd4af619a2fa45f5876d8855f7876cc09f663af
pkgdesc="Fcitx input method engine library"
url="https://github.com/fcitx/libime"
# armhf: extra-cmake-modules
arch="all !armhf"
license="LGPL-2.1-or-later"
depends_dev="boost-dev"
makedepends="
	$depends_dev
	cmake
	extra-cmake-modules
	fcitx5-dev
	samurai
	"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/fcitx/libime/archive/refs/tags/$pkgver.tar.gz
	kenlm-$_kenlm.tar.gz::https://github.com/kpu/kenlm/archive/$_kenlm.tar.gz
	"
options="net" # build fetches some checksummed language data itself, todo

prepare() {
	default_prepare

	rmdir src/libime/core/kenlm
	ln -sfv "$srcdir"/kenlm-$_kenlm src/libime/core/kenlm
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DENABLE_TEST="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

core() {
	pkgdesc="$pkgdesc (core module)"

	amove usr/lib/libIMECore.so.*
}

pinyin() {
	pkgdesc="$pkgdesc (pinyin module)"

	amove usr/lib/libIMEPinyin.so.*
}

table() {
	pkgdesc="$pkgdesc (table module)"

	amove usr/lib/libIMETable.so.*
}

sha512sums="
8ea0247d083e2a4ad4ad660d23b370891dcc087991f0f294f9a82da997b37ee16db0ec2a3e7a7976dfe246b7c95326529633f5d6bd45cfc4ac306819119dc9d2  libime-1.1.3.tar.gz
0ed68ed3b927b8c8353ab3815d17d0706b3357dce8a446176bd48ef6b73989bcf142983008e2b2b5e44769428a684dc1abcf3973f9f99c76b9bfc5f80a3aa363  kenlm-bcd4af619a2fa45f5876d8855f7876cc09f663af.tar.gz
"
